﻿#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <corecrt_wstdio.h>

using namespace std;

struct node
{
	int data;
	node* next;
};

int main()
{
	node* head = 0;
	node* p1;
	node* p2 = 0;
	node* p;

	for (int i = 1; i <= 5; i++)
	{
		p1 = (node*)malloc(sizeof(node));
		(*p1).data = i;
		if (head == 0)
		{
			head = p1;
			p2 = p1;
		}
		else
		{
			(*p2).next = p1;
			p2 = p1;
		}
	}
	(*p2).next = 0;

	p = head;
	printf("链表上各结点的数据为：\n");
	while (p != 0)
	{
		printf("%d ", (*p).data);
		p = (*p).next;
	}
	printf("\n");

	p1 = head;
	while ((*p1).data != 3)
	{
		p2 = p1;
		p1 = (*p1).next;
	}
	(*p2).next = (*p1).next;
	delete p1;

	p = head;
	printf("删除数据3节点后，链表上各结点的数据为：\n");
	while (p != 0)
	{
		printf("%d ", (*p).data);
		p = (*p).next;
	}
	printf("\n");

	int c = _getch();

	return 0;
}